<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div >
        <el-form size="small" label-width="70px" :rules="rules" ref="form" :model="crud.order"
                 >
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="单据编码">
                <el-input  v-model="crud.order.code" disabled placeholder="系统自动生成"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"
                  v-model="crud.order.busDate"
                  type="date"
                  style="width: 100%;"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户" prop="customerId">
                <zSelect :value.sync="crud.order.customerId" :showName="crud.order.customerName" @getChange="getInfo"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" url="api/dropDown/basCustomerList"  :params="{isContact:'0,2',customerAttr :'3'}"
                         style="width:  100%"/>
                <!--<el-select v-model="crud.order.customerId" class="edit-input"     style="width:  100%" placeholder="请选择客户" >-->
                  <!--<el-option-->
                    <!--v-for="(item,index) in dict.t_bas_customer_is_contact"-->
                    <!--:key="index"-->
                    <!--:label="item.label"-->
                    <!--:value="item.value"-->
                  <!--/>-->
                <!--</el-select>-->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="客户单号" prop="customerOrderCode" >
                 <el-input v-model="crud.order.customerOrderCode" :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"  style="width: 100%"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="业务员" prop="userId">
                <zSelect :value.sync="crud.order.userId" :showName="crud.order.userName"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" url="api/dropDown/sysUserList" :params="{deptId:crud.order.deptId}"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="销售部门" prop="deptId" label-width="80px">
                <zSelect :value.sync="crud.order.deptId" :showName="crud.order.deptName"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" url="api/dropDown/childSysDeptList"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="押箱金额">
                <el-input disabled  v-model="crud.order.pledgeBoxAmount"    placeholder=""></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="是否验收">
                <el-select v-model="crud.order.isAccept" :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"  placeholder="" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.common_yes_or_no"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>

<!--            <el-col :span="6">-->
<!--              <el-form-item label="二级代理">-->
<!--                <el-input disabled  v-model="crud.order.sourceCode"  disabled  placeholder="客户档案自动带出"></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="6">
              <el-form-item label="联系人">
                <el-input v-model="crud.order.contactName"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" placeholder="请输入"  />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="联系电话">
                <el-input v-model="crud.order.contactPhone"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" placeholder="请输入" maxlength="11"  oninput="value=value.replace(/[^\d]/g,'')" show-word-limit/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="入库仓库" prop="warehouseId">
                <zSelect :value.sync="crud.order.warehouseId"
                         :showName="crud.order.warehouseName"
                         :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"
                         url="api/dropDown/basWarehouseList"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>


            <el-col :span="6">
              <el-form-item label="送货地址">
                <el-input  v-model="crud.order.deliveryAddress"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"  placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="地址">
                <el-input  v-model="crud.order.address"   :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"  placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="单据说明">
                <el-input  v-model="crud.order.orderRemark"  :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"  placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="备注">
                <el-input  v-model="crud.order.remark"  :disabled="crud.order.isAccept === 1"  placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="状态">
                <el-select
                  v-model="crud.order.orderStatus"
                  class="filter-item"
                  clearable
                  disabled
                  placeholder="状态"
                  size="small"
                  style="width: 100%;"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="核销状态" prop="cancelStatus">
                <el-select
                  v-model="crud.order.cancelStatus"
                  class="filter-item"
                  clearable
                  disabled
                  placeholder="状态"
                  size="small"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in  dict.common_cancel_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="驾驶员">
                <zSelect :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" :value.sync="crud.order.driverUserId" :showName="crud.order.driverUserName" url="api/dropDown/sysUserList" :params="{businessAttr:'5'}"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
            <el-form-item label="配送单号">
              <el-input  v-model="crud.order.loadCode"  disabled ></el-input>
            </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="跟车员">
                <zSelect multiple :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'" :value.sync="crud.order.followUserIds" :showName="crud.order.followUserName" url="api/dropDown/sysUserList" :params="{businessAttr:'6'}"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属二批">
                <z-select :value.sync="crud.order.scustomerId"
                          :disabled="crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'"
                          url="/api/dropDown/sCustomerList"
                          :params="{ids:crud.order.customerId}"
                          :showName="crud.order.scustomerName"></z-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--   操作栏   -->
      <crudOperation :permission="permission">
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          v-if="addDetail"
          type="primary"
          @click="jumpAdd"
        >
          添加
        </el-button>
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          :disabled="crud.order.orderStatus==='PASS'"
          type="primary"
          @click="toAdd()"
        >
          新增
        </el-button>
        <!--        <el-button-->
        <!--          slot="left"-->
        <!--          class="filter-item"-->
        <!--          size="mini"-->
        <!--          type="success"-->
        <!--          :disabled="crud.selections.length !== 1"-->
        <!--          @click="toDeatil(crud.selections)"-->
        <!--        >修改-->
        <!--        </el-button>-->
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="primary"
          @click="submit()"
        >
          保存
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="primary"
          @click="toAddList"
        >
          批量新增
        </el-button>
        <el-button
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="warning"
          @click="crud.preView"
        >打印</el-button>
        <el-button
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="warning"
          @click="crud.preView1"
        >打印预览</el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          @click="crud.toAccept($route.params.id)"
          :disabled="$route.params.id == 'add' "
          v-permission="permission.accept"
        >
          回单验收
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          @click="crud.toUnAccept($route.params.id)"
          :disabled="$route.params.id == 'add' "
          v-permission="permission.accept"
        >
          取消验收
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="$route.params.id=='null'"
          :loading="crud.passLoading"
          @click="crud.doDetailPassOrReject('INVALID',id)"

        >
          <!--        v-permission="permission.pass"-->
          作废
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="$route.params.id=='null'"
          @click="crud.doDetailPassOrReject('RECOVER',id)"

        >
          <!--        v-permission="permission.reject"-->
          取消作废
        </el-button>
      </crudOperation>
      <!--      :summary-method="crud.getSummaries"-->
      <el-table ref="table" stripe border  v-loading="crud.loading" height="500" :row-class-name="crud.tableRowClassName"
                :data="crud.data"
                size="small" style="width: 100%;"
                :show-summary="true"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                highlight-current-row="highlight-current-row"
                @row-dblclick="switchRowIndex"
                sortable="custom"
                @sort-change="crud.sortChange"
                @selection-change="crud.selectionChangeHandler"
                >
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60" />
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 10px">{{scope.row[`${item.prop}`]}}</span>
              <span v-else-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-else-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
              <span v-else-if="item.type == 4"  >
              <span v-if="item.prop == 'goodsName'" style="display: flex;align-items: center" >
                <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.goodsName }}</span>
                <el-input v-else placeholder="请输入商品" v-model="scope.row.goodsName" />
              </span>
              <span v-else-if="item.prop == 'discountRate'"  >
                  <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.discountRate }}%</span>
                    <el-input v-if="scope.$index === rowIndex"
                              @input.native="crud.inuptCount(scope, 'discountRate')"
                              oninput="value=value.replace(/[^\d^\.]/g,'')"
                              maxlength="12"
                              v-model.lazy="scope.row.discountRate"
                              style="width: 100%"
                    >
                      <template slot="append">
                        %
                      </template>
                    </el-input>
              </span>
              <span v-else-if="item.prop == 'taxPrice'" style="display: flex;justify-content: center;align-items: center" >

                   <span v-if="scope.$index !== rowIndex || crud.order.isAccept === 1">{{ scope.row.taxPrice }}</span>
                      <el-input   oninput="value=value.replace(/[^\d^\.]/g,'')"
                                  maxlength="12" @input="crud.inuptCount(scope, 'taxPrice')" v-else v-model="scope.row.taxPrice"
                                  placeholder="请输入内容"
                      ></el-input>
              </span>
              <span v-else-if="item.prop == 'taxBoxPrice'"  style="display: flex;justify-content: center;align-items: center">
                <span v-if="scope.$index !== rowIndex || crud.order.isAccept === 1">{{ scope.row.taxBoxPrice }}</span>
                  <el-input v-else         oninput="value=value.replace(/[^\d^\.]/g,'')"
                            maxlength="12"  @input.native="crud.inuptCount(scope, 'taxBoxPrice')" v-model="scope.row.taxBoxPrice"
                            placeholder="请输入内容">
                  </el-input>
              </span>
              <span v-else-if="item.prop == 'goodsCount'"  >
                <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.goodsCount }}</span>
                <el-input v-else v-model="scope.row.goodsCount" @input="crud.computedMoney(scope.row)"
                          placeholder="请输入内容"></el-input>
              </span>
              <span v-else-if="item.prop == 'boxNum'"  >
                <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE' ">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>
                <el-input v-else
                          @input.native="crud.inuptCount(scope, 'boxNum')"
                          maxlength="12"
                          v-model="scope.row.boxNum"
                          style="width:49%;float: left">
                  <template slot="append">{{scope.row.boxUnitName}}</template>
                </el-input>
                  <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>
                  <el-input v-else
                            @input.native="crud.inuptCount(scope, 'mainNum')"
                            maxlength="12"
                            v-model="scope.row.mainNum"
                            style="width: 49%;float: right">
                    <template slot="append">{{scope.row.mainUnitName}}</template>
                  </el-input>
              </span>
            <span v-else-if="item.prop == 'warehouseName'" style="display: flex;justify-content: center;align-items: center" >
                <span >{{ scope.row.warehouseName }}</span>
<!--                <zSelect v-else v-model="scope.row.warehouseId" :showName="scope.row.warehouseName" class="edit-input"-->
<!--                         @change="crud.setProduct($event,scope,'warehouseName')" :value.sync="scope.row.warehouseId" url="api/dropDown/basWarehouseList" />-->
              </span>
            <span v-else-if="item.prop == 'storehouseName'"  >
               <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.storehouseName }}</span>
                <zSelect v-else :value.sync="scope.row.storehouseId" :showName="scope.row.storehouseName" @change="crud.setProduct($event,scope,'storehouseName')" :params="{warehouseId:scope.row.warehouseId}"  url="api/dropDown/basStorehouseList"    style="width: 100%;"/>
              </span>
            <span v-else-if="item.prop == 'goodsTagName'" style="display: flex;justify-content: center;align-items: center" >
              <span v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'">{{ scope.row.goodsTagName }}</span>
                <zSelect v-else :value.sync="scope.row.goodsTagId" :showName="scope.row.goodsTagName" :label="scope.row.goodsTagName"    @change="crud.setProduct($event,scope,'goodsTagName')" url="api/dropDown/basGoodsTagList"    style="width: 100%;"/>
              </span>
            <span v-else-if="item.prop == 'remark'"  >
          <span v-if="scope.$index !== rowIndex">{{ scope.row.remark }}</span>
          <el-input v-else v-model="scope.row.remark" type="textarea" style="width: 100%;"/>
              </span>
            <span v-else-if="item.prop == 'usableBoxNum'">
                <span>{{ scope.row.usableBoxNum || 0 }}{{ scope.row.boxUnitName }}</span>
                <span>{{ scope.row.usableMainNum || 0 }}{{ scope.row.mainUnitName }}</span>
            </span>
                <span v-else-if="item.prop == 'taxAmount'" class="flex a-item j-content">
              <span v-if="scope.$index !== rowIndex|| crud.order.isAccept === 1">{{ scope.row.taxAmount }}</span>
                <el-input v-else  oninput="value=value.replace(/[^\d^\.]/g,'')"
                          maxlength="12" @input.native="crud.inuptCount(scope, 'taxAmount')"
                          v-model="scope.row.taxAmount"
                          placeholder="请输入内容">
                </el-input>
            </span>
                </span>
            </template>
          </template>
        </el-table-column>



<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" width="200">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.goodsName }}</span>-->
<!--            <jtg-select-plus v-else ref="productRef"-->
<!--                             v-model="scope.row.goodsId"-->
<!--                             :initValue="scope.row.goodsName"-->
<!--                             :customerId="crud.order.customerId"-->
<!--                             typeName="SALE"-->
<!--                             :buyChannel ="crud.order.buyChannel"-->
<!--                             @remoteMethod="getValue($event,scope.$index)"-->
<!--                             @input="getInput($event,name,scope.$index)"-->
<!--                             @change="crud.productChange($event,scope)"-->
<!--                             url="productList"/>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('helpSign')" prop="helpSign" label="助记符" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('model')" prop="model" label="规格型号" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('barcode')" prop="barcode" label="条形码" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="分类" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="商品品牌" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTagName')" prop="goodsTagName" label="商品类型" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('packageType')"  label="包装类型" prop="packageType">-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.t_bas_goods_package_type,scope.row.packageType)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱装量" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="单位" width="100">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.mainUnitName }}</span>-->
<!--&lt;!&ndash;           <zSelect v-if="scope.row.isSelected" :value.sync="form.firstUnitId" :label="form.firstUnitName" url="api/dropDown/basUnitList">&ndash;&gt;-->
<!--&lt;!&ndash;            </zSelect>&ndash;&gt;-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="箱数" />-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="零数" >&ndash;&gt;-->
<!--&lt;!&ndash;        </el-table-column>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="辅数量" width="200">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'boxNum')"-->
<!--                      v-model="scope.row.boxNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.boxUnitName}}</template>-->
<!--            </el-input>-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'mainNum')"-->
<!--                      v-model="scope.row.mainNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.mainUnitName}}</template>-->
<!--            </el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCount')" prop="goodsCount" label="数量" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.goodsCount }}</span>-->
<!--&lt;!&ndash;            <el-input v-if="scope.row.isSelected"&ndash;&gt;-->
<!--&lt;!&ndash;                      @input.native="crud.inuptCount(scope, 'goodsCount')"&ndash;&gt;-->
<!--&lt;!&ndash;                      oninput="value=value.replace(/[^\d^\.]/g,'')"&ndash;&gt;-->
<!--&lt;!&ndash;                      maxlength="12"&ndash;&gt;-->
<!--&lt;!&ndash;                      v-model.lazy="scope.row.goodsCount"&ndash;&gt;-->
<!--&lt;!&ndash;                      style="width: 100%"/>&ndash;&gt;-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptGoodsCount')" prop="acceptGoodsCount" label="验收数量" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ scope.row.acceptGoodsCount }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptBoxCount')" prop="acceptBoxCount" label="验收箱数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptBoxNum')" prop="acceptBoxNum" label="验收箱单位数量" width="200">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'boxNum')"-->
<!--                      v-model="scope.row.boxNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.boxUnitName}}</template>-->
<!--            </el-input>-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'mainNum')"-->
<!--                      v-model="scope.row.mainNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.mainUnitName}}</template>-->
<!--            </el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptMainNum')" prop="acceptMainNum" label="验收主单位数量" width="200">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'boxNum')"-->
<!--                      v-model="scope.row.boxNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.boxUnitName}}</template>-->
<!--            </el-input>-->
<!--            <span v-if="!scope.row.isSelected || crud.order.orderStatus!=='SAVE'">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'mainNum')"-->
<!--                      v-model="scope.row.mainNum"-->
<!--                      style="width: 45%!important;">-->
<!--              <template slot="append" >{{scope.row.mainUnitName}}</template>-->
<!--            </el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->

<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTaxAmount')" prop="acceptTaxAmount" label="验收含税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptNoTaxAmount')" prop="acceptNoTaxAmount" label="验收未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTax')" prop="acceptTax" label="验收税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxPrice')" prop="taxPrice" label="单价" >-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected || crud.order.isAccept === 1">{{ scope.row.taxPrice }}</span>-->
<!--            <el-input v-else-->
<!--                      @input.native="crud.inuptCount(scope, 'taxPrice')"-->
<!--                      oninput="value=value.replace(/[^\d^\.]/g,'')"-->
<!--                      maxlength="12"-->
<!--                      v-model.lazy="scope.row.taxPrice"-->
<!--                      style="width: 100%"/>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxBoxPrice')" prop="taxBoxPrice" label="箱价" >-->
<!--          <template slot-scope="scope">-->
<!--            <span >{{ scope.row.taxBoxPrice }}</span>-->
<!--&lt;!&ndash;            <el-input v-if="scope.row.isSelected"&ndash;&gt;-->
<!--&lt;!&ndash;                      @input.native="crud.inuptCount(scope, 'taxBoxPrice')"&ndash;&gt;-->
<!--&lt;!&ndash;                      oninput="value=value.replace(/[^\d^\.]/g,'')"&ndash;&gt;-->
<!--&lt;!&ndash;                      maxlength="12"&ndash;&gt;-->
<!--&lt;!&ndash;                      v-model.lazy="scope.row.noTaxPrice"&ndash;&gt;-->
<!--&lt;!&ndash;                      style="width: 100%"/>&ndash;&gt;-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxAmount')" prop="taxAmount" label="含税金额" >-->
<!--&lt;!&ndash;          <template slot-scope="scope">&ndash;&gt;-->
<!--&lt;!&ndash;            <span v-if="!scope.row.isSelected">{{ scope.row.taxAmount }}</span>&ndash;&gt;-->
<!--&lt;!&ndash;            <el-input v-if="scope.row.isSelected"&ndash;&gt;-->
<!--&lt;!&ndash;                      oninput="value=value.replace(/[^\d^\.]/g,'')"&ndash;&gt;-->
<!--&lt;!&ndash;                      maxlength="12"&ndash;&gt;-->
<!--&lt;!&ndash;                      v-model.lazy="scope.row.taxAmount"&ndash;&gt;-->
<!--&lt;!&ndash;                      style="width: 100%"/>&ndash;&gt;-->
<!--&lt;!&ndash;          </template>&ndash;&gt;-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额" >-->
<!--&lt;!&ndash;          <template slot-scope="scope">&ndash;&gt;-->
<!--&lt;!&ndash;            <span v-if="!scope.row.isSelected">{{ scope.row.noTaxAmount }}</span>&ndash;&gt;-->
<!--&lt;!&ndash;            <el-input v-if="scope.row.isSelected"&ndash;&gt;-->
<!--&lt;!&ndash;                      oninput="value=value.replace(/[^\d^\.]/g,'')"&ndash;&gt;-->
<!--&lt;!&ndash;                      maxlength="12"&ndash;&gt;-->
<!--&lt;!&ndash;                      v-model.lazy="scope.row.noTaxAmount"&ndash;&gt;-->
<!--&lt;!&ndash;                      style="width: 100%"/>&ndash;&gt;-->
<!--&lt;!&ndash;          </template>&ndash;&gt;-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxRate ')" prop="tax" label="税率" >-->
<!--          <template slot-scope="scope">-->
<!--                <span>{{ scope.row.taxRate }}%</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('tax')" prop="tax" label="税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"  width="200">-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected">{{ scope.row.remark }}</span>-->
<!--            <el-input v-if="scope.row.isSelected"-->
<!--                      type="textarea"-->
<!--                      :rows="2"-->
<!--                      v-model.lazy="scope.row.remark"-->
<!--                      style="width: 100%"/>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <!--        v-permission="['admin','buyProtocolDetail:edit','buyProtocolDetail:del']"-->
        <el-table-column :render-header="crud.renderHeader"  label="操作" fixed="right" width="150px" align="center">
          <template slot-scope="scope">
            <!--              <el-button-->
            <!--                type="primary"-->
            <!--                icon="el-icon-plus"-->
            <!--                circle-->
            <!--                v-if="(crud.data.length-1)==scope.$index"-->
            <!--                :disabled="crud.order.orderStatus==='PASS'"-->
            <!--                @click="crud.addRow(scope.$index)"></el-button>-->
            <!--              v-if="crud.data.length!==1"-->
            <el-button
              slot="reference" class="el-icon-delete opration_icon_btn"
              :disabled="crud.order.orderStatus==='PASS'"
              style="border: none;width: auto;height: auto"
              @click="delAddRow(scope.$index)"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
<!--      <pagination />-->
      <el-dialog :close-on-click-modal="false" title="选择商品"
                 destroy-on-close
                 v-dialogDrag
                 close-on-press-escape
                 :visible.sync="showQueryGoods" append-to-body width="80vw">
        <j-goods-select @diaLogGoodsChange="changeGoods" :noReturnBox="false" :customerId="crud.order.customerId" type="SALE_RETURN" @closeDialog="closeDialog" v-if="showQueryGoods"  :queryGoods="queryGoods"></j-goods-select>
      </el-dialog>
      <!--批量新增弹窗-->
      <el-dialog
        title="请选择打印模板"
        :visible.sync="crud.printConfig.pringDialog"
        width="30%"
      >
        <jPrintConfig groupId="wareReturnBottleBox"
                      v-if="crud.printConfig.pringDialog"
                      @getPrintId="crud.detailedPrint"
                      :isPreview="crud.printConfig.isPreview"
        ></jPrintConfig>
      </el-dialog>
      <el-dialog :close-on-click-modal="false" title="商品新增"
                 :visible.sync="showAddBatchDialog" append-to-body width="100vw">
        <add-batch v-if="showAddBatchDialog" :showAddBatchDialog.sync="showAddBatchDialog" :list="detailList"
                   :params="{customerId:crud.order.customerId,type:'SALE',}"
                   @change="afterChangeGoods"></add-batch>
      </el-dialog>
    </div>
    <vue-context-menu :contextMenuData="contextMenuData"
                      @tableConfig="tableConfig"
                      @deletedata="deletedata"></vue-context-menu>

    <!-- 表格配置 -->
    <el-dialog title="表格配置"
               :visible.sync="tableConfigShow"
               width="60%">
      <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
    </el-dialog>
  </div>
</template>

<script>
import crudWareReturnBottleBoxDetail from '@/api/erp/wareReturnBottleBox'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import jtgSelectPlus from '@/components/select/JtgSelectPlus'
import { getCompany } from '@/api/system/company'
import {Notification} from "element-ui";
import addBatch from '@/components/addBatch/addBatch'
import jPrintConfig from "../../../components/jPrintConfig/jPrintConfig";
import Vue from 'vue'
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
import {salesDetailKey} from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import jGoodsSelect from "@/components/jGoodsSelect/jGoodsSelect";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '采购单明细',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: true,
    enable: false,
    disable: false,
    pass: true,
    reject: true,
    recover: false,
    invalid: false,
    print: true,
    printDetail: true,
  },
  params() {
    const href = location.href.split('/')
    return {
      id: href[href.length - 1] == 'add' ? 0 : href[href.length - 1], page: 0, size: 999,
    }
  },
  url: 'api/wareReturnBottleBox/detail',name:'wareReturnBottleBoxDetail', sort:'t.seq,asc', crudMethod: { ...crudWareReturnBottleBoxDetail }})

const defaultForm = { id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null, firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null, cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null }
export default {
  name: 'wareReturnBottleBoxDetail',
  components: { pagination, crudOperation, rrOperation, udOperation,jtgSelectPlus,addBatch,jPrintConfig, jTableColumnConfig, jGoodsSelect},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), tablemixins, salesDetailKey],
  dicts: ['t_buy_order_source_type','t_bas_customer_is_contact','common_yes_or_no','t_buy_order_type','common_order_status','t_buy_order_buy_channel','common_cancel_status','t_bas_goods_package_type'],

  data() {
    return {
      id: null,
      detailList:[],
      permission: {
        add: ['admin', 'wareReturnBottleBoxDetail:add'],
        edit: ['admin', 'wareReturnBottleBoxDetail:edit'],
        del: ['admin', 'wareReturnBottleBoxDetail:del'],
        import: ['admin', 'wareReturnBottleBoxDetail:import'],
        export: ['admin', 'wareReturnBottleBoxDetail:export'],
        copy: ['admin', 'wareReturnBottleBoxDetail:copy'],
        upload: ['admin', 'wareReturnBottleBoxDetail:upload'],
        download: ['admin', 'wareReturnBottleBoxDetail:download'],
      },
      rules: {
        deptId: [
          { required: true, message: '采购部门不能为空', trigger: 'blur' }
        ],
        acceptDate: [
          { required: true, message: '到货日期不能为空', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '采购单类型不能为空', trigger: 'blur' }
        ],
        buyChannel: [
          { required: true, message: '渠道类型不能为空', trigger: 'blur' }
        ],
        // sourceType: [
        //   { required: true, message: '来源类型不能为空', trigger: 'blur' }
        // ],
        customerId: [
          { required: true, message: '客户不能为空', trigger: 'blur' }
        ],
        // userId: [
        //   { required: true, message: '业务员不能为空', trigger: 'blur' }
        // ],
        isAppend: [
          { required: true, message: '是否追加不能为空', trigger: 'blur' }
        ],
        isContact: [
          { required: true, message: '是否第三方采购不能为空', trigger: 'blur' }
        ],
      },
      addRowData:{
        isSelected: true,id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null, firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null, cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null
      },
      addDetail: false,
      showAddBatchDialog: false,
      productList:[],
      queryGoods:{
        keyword:'',
        index:null,
        goodsTagName:'回瓶回箱,瓶盖',
        type: 'SALE_RETURN'
      },

    }
  },
  watch: {
  },
  destroyed() {
    this.crud.setItemInfo("wareReturnBottleBoxDetail_add")
  },
  activated() {
    //获取上次进入Id
    const id = sessionStorage.getItem(this.$options.name + 'Id')
    //记录本次进入的Id
    sessionStorage.setItem(this.$options.name+'Id',this.$route.params.id)
    if (!this.crud.header) this.getHeader()
    if(id !== this.$route.params.id){
      this.addDetail = !/add$/.test(window.location.href)
      if(this.$route.params.id === 'add'){
        if( this.crud.getItemInfo("wareReturnBottleBoxDetail_add")){
        return false
      }
      this.crud.order = {
        id: null,
        code: '',
        busDate:  this.getTime(),
        // createTime: this.getTime(),
        name: '',
        userId: '',
        deptId: null,
        type: 1,
        buyChannel: 1,
        cancelStatus: 0,
        acceptDate: null,
        isContact: null,
        isAppend: null,
        orderStatus: 'SAVE',
        index: '0',
        customerId:'',
        contactName:'',
        contactPhone:'',
        orderRemark: null,
        address: null,
        deliveryAddress: null,
        warehouseId:null,
        pledgeBoxAmount:null,
        startDate: null,
        endDate: null,
        remark: ''
      }
      }else {
        this.crud.params.id = this.$route.params.id
        this.crud.refresh()
      }
    }else{
      this.init()
      this.$forceUpdate()
    }
  },
  created(){
    
    this.crud.headerInfo = {
      code:'wareReturnBottleBoxDetail',
      userId:this.$store.state.user.user.userId,
      path: "api/wareReturnBottleBox/detail",
    }
    if(/add$/.test(window.location.href)){
      this.getHeader()
    }
    this.addDetail = !/add$/.test(window.location.href)
    if (this.$route.params.id == 'add') {
      if( this.crud.getItemInfo("wareReturnBottleBoxDetail_add")){
        return false
      }
      this.crud.order = {
        id: null,
        code: '',
        busDate:  this.getTime(),
        // createTime: this.getTime(),
        name: '',
        userId: '',
        deptId: null,
        type: 1,
        buyChannel: 1,
        cancelStatus: 0,
        acceptDate: null,
        isContact: null,
        isAppend: null,
        orderStatus: 'SAVE',
        index: '0',
        customerId:'',
        contactName:'',
        contactPhone:'',
        orderRemark: null,
        address: null,
        deliveryAddress: null,
        warehouseId:null,
        pledgeBoxAmount:null,
        startDate: null,
        endDate: null,
        remark: ''
      }
      // this.crud.data.push(JSON.parse(JSON.stringify(this.addRowData)))
    }
  },
  beforeUpdate() {
    if (this.$route.params.id != 'add') {
      this.id = this.$route.params.id
      this.query.id = this.id
      this.crud.order.id = this.id
    }
  },
  methods: {
    getHeader(){
      const data ={
        modelName:'wareReturnBottleBoxDetail',
        url: "api/wareReturnBottleBox/detail",
        userId:this.$store.state.user.user.userId,
      }
      getHeaderProperties(data).then(res=>{
        this.crud.header = JSON.parse(res.data.header.content)
        this.$forceUpdate()
      }).catch(err=>{console.log(err)})
    },
    changeGoods(val){
      this.showQueryGoods = false
      this.crud.diaLogGoodsChange(val)
      this.$refs.table.setCurrentRow(this.crud.data[this.rowIndex])
    },
    init(){
      this.crud.order = {
        id: null,
        code: '',
        busDate:  this.getTime(),
        // createTime: this.getTime(),
        name: '',
        userId: '',
        deptId: null,
        type: 1,
        buyChannel: 1,
        cancelStatus: 0,
        acceptDate: null,
        isContact: null,
        isAppend: null,
        orderStatus: 'SAVE',
        index: '0',
        customerId:'',
        contactName:'',
        contactPhone:'',
        orderRemark: null,
        address: null,
        deliveryAddress: null,
        warehouseId:null,
        pledgeBoxAmount:null,
        startDate: null,
        endDate: null,
        remark: ''
      }
      this.crud.data = []
    },
    afterChangeGoods(goods) {
      this.showAddBatchDialog = false
      //去重，已经去重
      let arr = this.crud.data.map(detail=>detail.goodsId)
      let _goods = []
      let result = []
      goods.forEach(good => {
        // if(!arr.includes(goods.goodsId)){
        good.isSelected = true
        this.crud.data.push(good)
        // }
      })
      // this.calcuForm()
    },
    switchRowIndex(row) {
        if (row.index === this.rowIndex) {
          this.rowIndex = -1
          return
        }
        this.rowIndex = row.index
    },
    toAddList() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          //校验通过
          this.showAddBatchDialog = true
        } else {
          if (!this.crud.order.customerId) {
            this.$message.error("请先选择客户")
          }
          if (!this.crud.order.type) {
            this.$message.error("请先选择销售单类型")
          }
          // if (!this.crud.order.buyChannel) {
          //   this.$message.error("请先选择采购渠道")
          // }
        }
      })
    },
    getInfo(e){
      this.crud.order.warehouseId = e.warehouseId
      this.crud.order.scustomerId = null
      this.crud.order.contactName = e.contactName
      this.crud.order.contactPhone = e.contactPhone
      this.crud.order.deliveryAddress = e.deliveryAddress
      this.crud.order.address = e.address
      this.crud.order.deptId = e.deptId
      this.crud.order.deptName = e.deptName
      this.crud.order.userId = e.userId
      this.crud.order.userName = e.userName
      if (e.scustomerList){
        this.crud.order.scustomerId = e.scustomerList[0].scustomerId
        this.crud.order.scustomerName = e.scustomerList[0].scustomerName
      }else {
        this.crud.order.scustomerId = null
        this.crud.order.scustomerName = null
        console.log("设置成功")
      }
    },
    delAddRow(i){
      if(this.$route.params.id !== 'add'){
        this.$confirm('此操作将直接删除此条产品记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.crud.delRow(i)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
      }else{
        this.crud.delRow(i)
      }
    },
    getValue(e,i){
      console.log('this.crud.data',this.crud.data )
      this.crud.data[i].productName = e
      // let temp = this.crud.data[2]
      // this.crud.data[3] = temp
      this.crud.data.map(item => {
        // item.existId = 0
        // item.existNum = 0
        if(item.existBox === null){
          item.existBox = 0
        }
        if(item.occupyBox === null){
          item.occupyBox = 0
        }
      })
    },
    getInput(e,name,i){
      console.log(',data.goodsName',e,name,i)
      if(this.crud.data){
        if(e){
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId= e
        }else{
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId= null
        }
      }
    },
    // 保存
    submit(){
      var oDate1 = new Date(this.crud.order.startDate);
      var oDate2 = new Date(this.crud.order.endDate);
      if(oDate1.getTime() > oDate2.getTime()){
        this.$message({
          message: '开始日期不能大于结束日期',
          type: 'warning'
        })
        this.crud.order.startDate = null
        this.crud.order.endDate = null
        return false
      }
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        const table_rules = [
          // {name: '数量', value: 'goodsCount'},
          // {name: '销售价', value: 'taxPrice'},
          // {name: '未税单价', value: 'noTaxPrice'},
          // {name: '含税金额', value: 'taxAmount'},
          // {name: '未税金额', value: 'noTaxAmount'}
        ]
        const result = table_rules.some(({name, value}) => {
          const rules = this.$refs.table.data.some((item, index) => {
            if (!this.tableRules((index + 1), name, item[value])) return true
          })
          if (rules) return true
        })
        if (!result) this.save()
      })
    },
    tableRules(index, name, value) {
      if (!value) {
        Notification.error({title: '序号【' + index + '】' + name + '不能为空'})
        return false
      } else return true
    },
    getTime(date = new Date()){
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? ('0' + m) : m;
      var d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      var h = date.getHours();
      h=h < 10 ? ('0' + h) : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? ('0' + minute) : minute;
      var second=date.getSeconds();
      second=second < 10 ? ('0' + second) : second;
      // +' '+h+':'+minute+':'+second;
      return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second
    },
    closeDialog(val){
      this.showQueryGoods = false
    },
    jumpAdd(){
      this.$router.push({ path: '/ware/wareReturnBottleBoxDetail/add' })
    },
    //保存
    save() {
      let that = this
      that.crud.loadingOpen()
      this.crud.order.detailList  = this.crud.data
      this.crud.order.detailList.forEach(item=>{
        item.warehouseId = this.crud.order.warehouseId
      })
      let params = this.crud.order
      if (this.crud.order.orderStatus  !== 'SAVE'){
        params. isEditWithoutReject = 1
      }

      crudWareReturnBottleBoxDetail.add(params).then(res => {
        if(res.success){
          this.crud.order  = res.data
          this.isSave = true
          sessionStorage.removeItem(this.$options.name+'add')
          console.log('删除成功')
          // this.crud.data = res.data.detailList
          let id=res.data.id
          if(this.$route.params.id == 'add'){
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.push({params: {id}})
            this.crud.cleanItemInfo('wareReturnBottleBoxDetail_add')
          }
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          that.crud.loadingClose()
          this.crud.refresh()
        }else{
          that.crud.loadingClose()
          this.$message({
            message: res.msg,
            type: 'warning'
          })
        }

      }).catch((res)=>{
        that.crud.loadingClose()
      })
    },
    dbClick(row){
      row.isSelected = !row.isSelected
      const data = this.$refs['table'].data
      Vue.set(data, row.index, data[row.index])
    },

    // 新增
    toAdd(){

      if(!this.crud.order.customerId){
        this.$message({
          message: '请先选择客户',
          type: 'error'
        })
        return false
      }
      if(!this.crud.order.type){
        this.$message({
          message: '请先选择采购单类型',
          type: 'error'
        })
        return false
      }
      // if(!this.crud.order.buyChannel){
      //   this.$message({
      //     message: '请先选择采购渠道',
      //     type: 'error'
      //   })
      //   return false
      // }
      this.crud.data.push({
        isSelected: true,id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null, firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null, cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null,boxNum: null ,mainNum: null
      })
    },
    //修改
    toDetail(){
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>

